<script lang="ts" setup>
import { get, post, message, loadFile, formatOptions } from '@/utils'
import { FormInstance } from '@arco-design/web-vue'
import { WithdrawType } from '@/enum/config'
const props = defineProps<{
  show: boolean
  id: number | string
}>()
const emit = defineEmits(['update:show', 'reset', 'confirm'])
const formRef = ref() as Ref<FormInstance>
const detail = reactive({
  account: '',
  amount: 0,
  bank: '',
  realName: '',
  type: WithdrawType.微信,
})
const submit = done => {
  formRef.value.validate(err => {
    if (!err) {
      const query = Object.assign({}, detail)
      post(
        { url: '/server-shop/sys-seller/withdraw/save', data: query },
        ({ code, msg }) => {
          message({
            type: code == 200 ? 'success' : 'error',
            content: msg,
          })
          if (code == 200) {
            emit('update:show', false)
            emit('confirm')
          }
          done(code == 200)
        },
        () => done(false)
      )
    } else done(false)
  })
}
const getInfo = () => {
  get({ url: '/server-shop/sys-seller/withdraw/info', data: { id: props.id } }, ({ data }) => {
    Object.assign(detail, data)
  })
}
onMounted(() => {
  if (props.id) getInfo()
})
</script>
<template>
  <CDrawer v-model:visible="props.show" @before-ok="submit" :mask-closable="false" width="500px" :footer="!props.id" :title="$props.id ? '查看' : '提现申请'" @cancel="emit('update:show', false)">
    <div class="content">
      <a-form :model="detail" ref="formRef" :disabled="!!props.id" :label-col-props="{ span: 6 }" :wrapper-col-props="{ span: 16 }">
        <a-form-item label="提现金额" field="amount" :rules="[{ required: true, message: '请输入提现金额' }]" :validate-trigger="['change', 'blur']">
          <a-input-number v-model="detail.amount" placeholder="请输入提现金额" :min="0.1" />
        </a-form-item>
        <a-form-item label="收款方式">
          <a-select v-model="detail.type" :options="formatOptions(WithdrawType)" placeholder="请选择" />
        </a-form-item>
        <a-form-item v-if="detail.type == WithdrawType.银行卡" label="银行名称" field="bank" :rules="[{ required: true, message: '请输入提现金额' }]" :validate-trigger="['change', 'blur']">
          <a-input v-model="detail.bank" placeholder="请输入银行名称" :min="0.1" />
        </a-form-item>
        <a-form-item label="收款账号" field="account" :rules="[{ required: true, message: '请输入收款账号' }]" :validate-trigger="['change', 'blur']">
          <a-input v-model="detail.account" placeholder="请输入收款账号" :min="0.1" />
        </a-form-item>
        <a-form-item label="收款姓名" field="realName" :rules="[{ required: true, message: '请输入收款姓名' }]" :validate-trigger="['change', 'blur']">
          <a-input v-model="detail.realName" placeholder="请输入收款姓名" />
        </a-form-item>
      </a-form>
    </div>
  </CDrawer>
</template>
<style lang="less" scoped></style>
